import React, { Component } from 'react';
import {
    View,
    Text,
    Image,
    TouchableOpacity,
} from 'react-native';
import { homesevenStyle as styles } from '../../../../styles';
import {common_url} from "../../../util/fetch";
var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;
export default class Homeseven_1 extends Component {
    // 初始化模拟数据
    constructor(props) {
        super(props);
    }
    //list子项加载方法
    render() {
        if (this.props.company != undefined) {
            return (
                <TouchableOpacity
                    style={styles.seveneveryall}
                    onPress={() => { this.goGet('Company', this.props.company.companyId) }}
                    activeOpacity={1}>
                    <View>
                        <Text style={styles.fivename}>{this.props.company.companyName}</Text>
                        <View style={styles.seventa}>
                            <Text style={styles.fivelei}>{this.fieldName(this.props.company.domains, 3)}</Text>
                        </View>
                        <View style={styles.sevenetb}>
                            {this.welfareName(this.props.company.welfares, 3)}
                        </View>
                    </View>
                    <Image source={
                        this.props.company.companyPicture ?
                            {uri: common_url + "uploadImg/" + this.props.company.companyPicture}
                            : require('../../../img/app/company.png')} style={styles.head} />
                </TouchableOpacity>
            )
        } else {
            return null;
        }
    }
    goGet(name, id) {
        this.props.navigation.navigate(name, { useId: id });
    }

    //经营领域
    fieldName(List, sl) {
        var data = {
            cont: List
        }
        var arr = '';
        var s = sl;
        var length = data.cont.length
        if (length <= s) {
            s = length
        }
        for (var i = 0; i < s; i++) {
            arr += data.cont[i].field.fieldName + '/'
        }
        if (arr.endsWith('/')) {
            arr = arr.substr(0, arr.length - 1);
        }
        return arr;
    }

    //待遇
    welfareName(List, sl) {
        var data = {
            cont: List
        }
        var arr = [];
        var s = sl;
        var length = data.cont.length
        if (length <= s) {
            s = length
        }
        for (var i = 0; i < s; i++) {
            arr.push(
                <Text key={i} style={styles.fivenon}>{data.cont[i].welfareName}</Text>
            )
        }
        return arr;
    }

}